package com.googlecode.curvedmetromaps.core.logic.forcedriven;

import java.util.HashMap;

public abstract class ForceSubsystem {
	protected ForceSystem	system;

	public final static String	name	= "Base Force";

	public HashMap<String, ForceWeight>	weights = new HashMap<String, ForceWeight>();

	public ForceWeight baseWeight = new ForceWeight("Base weight", 1);
	public ForceWeight maxForce = new ForceWeight("Max force", 1);
	
	/**
	 * Instantiates a new force subsystem and sets a reference to the parent
	 * system.
	 * @param system Parent system to which this subsystem belongs.
	 */
	public ForceSubsystem(ForceSystem system) {
		this.system = system;
		createWeight("maxForce", "Maximum force", 1);
	}

	/**
	 * Applies forces on the ForceSystem.
	 * @param delta Time in milliseconds that has passed since last update.
	 */
	abstract void applyForces(int delta);

	/**
	 * Creates weight (removes one if already present using this key).
	 * @param key The key under which the weight is to be stored.
	 */
	protected void createWeight(String key, String label, double value) {
		if (weights.containsKey(key))
			weights.remove(key);

		weights.put(key, new ForceWeight(label, value));
	}	

	/**
	 * Sets or adds a weight
	 * @param key The key under which the weight is stored.
	 */
	protected void setWeight(String key, double value) {
		if (weights.containsKey(key))
			weights.get(key).value = value;
		else
			weights.put(key, new ForceWeight("", value));
	}	

	/**
	 * Gets the value of a weight
	 * @param key The key under which the weight is stored.
	 */
	protected double getWeight(String key) {
		return weights.get(key).value;
	}	
}
